package com.sunfield.windpower.fragment;

import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.sunfield.baseframe.base.BaseFragment;
import com.sunfield.baseframe.http.HttpResult;
import com.sunfield.baseframe.util.JsonUtil;
import com.sunfield.windpower.R;
import com.sunfield.windpower.adapter.GuideAdapter;
import com.sunfield.windpower.bean.GuideInfo;
import com.sunfield.windpower.decoration.SpaceDecoration;
import com.sunfield.windpower.http.HttpClient;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Bean;
import org.androidannotations.annotations.EFragment;
import org.androidannotations.annotations.ViewById;

import java.util.List;

/**
 * 首页 导航
 * Created by DELL on 2017/2/6.
 */
@EFragment(R.layout.fragment_guide)
public class GuideFragment extends BaseFragment {
    @ViewById
    RecyclerView rv_guide;

    @Bean
    GuideAdapter adapter;
    @Bean
    HttpClient http;

    @AfterViews
    void init(){
        rv_guide.setLayoutManager(new GridLayoutManager(getActivity(), 4));
        rv_guide.addItemDecoration(new SpaceDecoration(100, SpaceDecoration.TYPE_START));

        rv_guide.setAdapter(adapter);

        http.getMenuList();
    }

    @Override
    public void onHttpResult(HttpResult result) {
        super.onHttpResult(result);
        if(result.match(http, "getMenuList")){
            if(result.isSuccess()){
                List<GuideInfo> guideInfoList = JsonUtil.GetEntityS(JsonUtil.GetJsonArrayByLevel(result.getJson(), "data"), GuideInfo.class);
                adapter.updateData(guideInfoList);
            }
        }
    }
}
